package com.study.sxc.Dao;

import com.study.sxc.Entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface IUserDao {
    @Select({
        "<script>",
        "SELECT user_id AS userId, name, contact, student_id AS studentId",
        "FROM Users",
        "WHERE user_id IN",
        "<foreach collection='list' item='id' open='(' separator=',' close=')'>",
        "#{id}",
        "</foreach>",
        "</script>"
    })
    List<User> getUsers(List<Integer> ids);

    @Insert("INSERT INTO Users (name, contact, student_id) VALUES (#{name}, #{contact}, #{studentId})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int addUser(User user);

    @Update("UPDATE Users SET name = #{name}, contact = #{contact}, student_id = #{studentId} WHERE user_id = #{userId}")
    int updateUser(User user);

    @Delete("DELETE FROM Users WHERE user_id = #{id}")
    int deleteUser(Integer id);

    @Select("SELECT user_id AS userId, name, contact, student_id AS studentId FROM Users WHERE user_id = #{id}")
    User getUserById(Integer id);

    @Select("SELECT user_id AS userId, name, contact, student_id AS studentId FROM Users")
    java.util.List<User> getAllUsers();
} 